import { AppState } from '@/stores/interface'
import { DEFAULT_SETTING } from '@/constants'
import { pinia } from '../index'

export const useAppStore = defineStore('eco-app', {
  state: (): AppState => ({
    // 顶部菜单激活路径
    activeTopMenuPath: '/',
    isCollapse: false,
    language: DEFAULT_SETTING.language
  }),
  getters: {
    getActiveTopMenuPath: state => state.activeTopMenuPath,
    getCollapse: state => state.isCollapse,
    getLanguage: state => state.language
  },
  actions: {
    setCollapse(val: boolean) {
      this.isCollapse = val
    },
    setLanguage(val: string) {
      this.language = val
    },
    activeTopMenu(val: string) {
      this.activeTopMenuPath = val
    }
  },
  persist: true
})

export function useAppStoreWithOut() {
  return useAppStore(pinia)
}
